//
//  CZChatImgView.m
//  bubbleImgView
//
//  Created by Alvechen on 16/4/12.
//  Copyright © 2016年 alvechen. All rights reserved.
//

#import "CZChatImgView.h"

@interface CZChatImgView ()

@property (nonatomic,strong) UIImage  *image;

@property (nonatomic,assign) BOOL isOutgoing;

@end

@implementation CZChatImgView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
//    kCGBlendModeClear,                  /* R = 0 */
//    kCGBlendModeCopy,                   /* R = S */
//    kCGBlendModeSourceIn,               /* R = S*Da */
//    kCGBlendModeSourceOut,              /* R = S*(1 - Da) */
//    kCGBlendModeSourceAtop,             /* R = S*Da + D*(1 - Sa) */
//    kCGBlendModeDestinationOver,        /* R = S*(1 - Da) + D */
//    kCGBlendModeDestinationIn,          /* R = D*Sa */
//    kCGBlendModeDestinationOut,         /* R = D*(1 - Sa) */
//    kCGBlendModeDestinationAtop,        /* R = S*(1 - Da) + D*Sa */
//    kCGBlendModeXOR,                    /* R = S*(1 - Da) + D*(1 - Sa) */
//    kCGBlendModePlusDarker,             /* R = MAX(0, (1 - D) + (1 - S)) */
//    kCGBlendModePlusLighter             /* R = MIN(1, S + D) */
    
    
    //先画出的图(已经渲染出去)-D
//    UIImage *img = [UIImage imageNamed:@"nvshen"];
    [self.image drawInRect:rect];
    
    
    //即将画出的(即将渲染出去)-S   R:最终结果
    UIImage *bubbleImg = nil;
    
    //根据方向画气泡
    if (self.isOutgoing) {
        
        bubbleImg = [UIImage imageNamed:@"SenderTextNodeBkg"];
        
    }else{
    
        bubbleImg = [UIImage imageNamed:@"ReceiverTextNodeBkg"];
    }
    
    [bubbleImg drawInRect:rect blendMode:kCGBlendModeDestinationIn alpha:1.0];
    
}

- (void)setImage:(UIImage *)image isOutgoing:(BOOL)isOutgoing{
    
    _image = image;
    _isOutgoing = isOutgoing;

    [self setNeedsDisplay];
}


@end
